/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.Arrays;

/**
 * <p>Project: jse2303 - ArrSort1
 * <p>Powered by webrx On 2023-07-12 11:00:51
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrSort3 {
    public static void main(String[] args) {

        //Student(id,name,score)
        String[] ns = {"java", "c", "go", "ruby", "python", "c++", "php", "javascript"};
        System.out.println(Arrays.toString(ns));
        //升序
        Arrays.sort(ns);

        Arrays.sort(ns, (a, b) -> a.compareTo(b));
        System.out.println(Arrays.toString(ns));

        //降序
        Arrays.sort(ns, (a, b) -> b.compareTo(a));
        System.out.println(Arrays.toString(ns));


        //根据字符个数升序
        Arrays.sort(ns, (a, b) -> a.length() - b.length());
        System.out.println(Arrays.toString(ns));


        //根据字符个数升序
        Arrays.sort(ns, (a, b) -> b.length() - a.length());
        System.out.println(Arrays.toString(ns));

        //洗牌
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(ns, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println(Arrays.toString(ns));

    }
}
